package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.NewsTypeService;
import com.wanxi.vo.NewsTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/newsType")
@CrossOrigin(origins = "http://localhost:8081")
public class NewsTypeController {
    @Autowired
    NewsTypeService newsTypeService;

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('insertNewsType')")
    public ResultDTO addNewsType(NewsTypeVO newsTypeVO){
        return newsTypeService.addNewsType(newsTypeVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteNewsType')")
    public ResultDTO deleteNewsType(NewsTypeVO newsTypeVO){
        return newsTypeService.deleteNewsType(newsTypeVO);
    }

    @GetMapping("/findAll")
    public ResultDTO findAllNewsType(){
        return newsTypeService.findAllNewsType();
    }

    @PostMapping("/findById")
    public ResultDTO findNewsTypeById(NewsTypeVO newsTypeVO){
        return newsTypeService.findNewsTypeById(newsTypeVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateNewsType')")
    public ResultDTO updateNewsTypeEnable(NewsTypeVO newsTypeVO){
        return newsTypeService.updateEnable(newsTypeVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateNewsType')")
    public ResultDTO updateNewsType(NewsTypeVO newsTypeVO){
        return newsTypeService.updateNewsType(newsTypeVO);
    }
}
